from io import BytesIO

from sqlalchemy.orm import Session

from app.yg_crm.crud import get_check_bill_by_billNos
import pandas as pd
from openpyxl import load_workbook
from datetime import datetime

def getBillDetailByBillNo(db: Session, billNos: list):
     res = get_check_bill_by_billNos(db, ids=billNos)
     # print(res)
     return res



async def getExcelFileCreateYear(file_path:BytesIO):
     # 读取Excel文件
     df = pd.read_excel(file_path, dtype=str)

     # 使用openpyxl加载工作簿
     workbook = load_workbook(file_path)
     properties = workbook.properties

     # 获取文件的创建日期
     creation_date = properties.created
     creation_date_str = creation_date.strftime('%Y-%m-%d')
     return creation_date_str[:4]


# 批量创建或更新对象
def add_or_update_records(session, ormObjects):
    for o in ormObjects:
        session.merge(o)
    session.commit()


